package fr.uniscol.siecle.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Eleves extends FichierSIECLE implements Serializable {

	private List<Eleve> eleves = null;
	
	private List<OptionEleve> optionsEleve = null;
	
	private List<StructureEleve> structuresEleve = null;
	
	private Map<String, Bourse> bourses = null;
	
	private List<Adresse> adresses = null;

	public List<Eleve> getEleves() {
		if(eleves == null){
			eleves = new ArrayList<Eleve>();
		}
		return eleves;
	}

	public void setEleves(List<Eleve> eleves) {
		this.eleves = eleves;
	}

	public List<OptionEleve> getOptionsEleve() {
		if(optionsEleve == null){
			optionsEleve = new ArrayList<OptionEleve>();
		}
		return optionsEleve;
	}

	public void setOptionsEleve(List<OptionEleve> optionsEleve) {
		this.optionsEleve = optionsEleve;
	}

	public List<StructureEleve> getStructuresEleve() {
		if(structuresEleve == null){
			structuresEleve = new ArrayList<StructureEleve>();
		}
		return structuresEleve;
	}

	public void setStructuresEleve(List<StructureEleve> structuresEleve) {
		this.structuresEleve = structuresEleve;
	}

	public Map<String, Bourse> getBourses() {
		return bourses;
	}

	public void setBourses(Map<String, Bourse> bourses) {
		this.bourses = bourses;
	}

	public List<Adresse> getAdresses() {
		if(adresses == null){
			adresses = new ArrayList<Adresse>();
		}
		return adresses;
	}

	public void setAdresses(List<Adresse> adresses) {
		this.adresses = adresses;
	}

	public Eleve findEleve(String codeEleve) {
		for(Eleve e : getEleves()){
			if(e.getId().equals(codeEleve)){
				return e;
			}
		}
		return null;
	}
	
	public List<Option> getOptionsOfEleve(String eleveId){
		
		List<Option> options = new ArrayList<Option>();
		 
		for(OptionEleve opt : getOptionsEleve()){
			if(opt.getEleve().getId().equals(eleveId)){
				options.addAll(opt.getOptions());
			}
		}
		return options;
	}
	
	public List<Division> getStructuresOfEleve(String eleveId){
		
		List<Division> structures = new ArrayList<Division>();
		
		for(StructureEleve ste : getStructuresEleve()){
			if(ste.getEleve().getId().equalsIgnoreCase(eleveId)){
				structures.add(ste.getStructure());
			}
		}
		
		return structures;
	}
}
